package cn.ilikes.tools.hbase.jpa.clazzes;

import java.io.InputStream;
import java.net.URL;

import org.slf4j.Logger;

import cn.ilikes.tools.hbase.jpa.clazzes.resources.IJPAHBaseResources;
import cn.ilikes.tools.hbase.jpa.clazzes.resources.JPAHBaseResources;
import cn.ilikes.tools.hbase.jpa.clazzes.resources.ResourcesloadListener;
import cn.ilikes.tools.logs.Loggerfactory;

public abstract class ABJPAHbaseClassLoader extends ClassLoader implements IJPAHbaseClassLoader {

	private static Logger logger = Loggerfactory.instance(ABJPAHbaseClassLoader.class);

	private IJPAHBaseResources hBaseResources = new JPAHBaseResources();

	public ABJPAHbaseClassLoader(ClassLoader parentClassLoader) {
		super(parentClassLoader);
		init();
	}

	protected abstract void init();

	@Override
	public void loadResources(URL url) {
		if (Loggerfactory.isdebug(logger))
			Loggerfactory.debug(logger, "hbase classloader load resource ! " + url.toString());
		hBaseResources.loadResources(url);

	}

	protected void addResourcesloadListener(ResourcesloadListener resourcesloadListener) {
		hBaseResources.addResourcesloadListener(resourcesloadListener);
	}

	public InputStream getResourceAsStream(String name) {
		return super.getResourceAsStream(name);
	}

}
